package com.st.buy.manager.controller;

import com.st.buy.pojo.TbContent;
import com.st.buy.util.pojo.BuyResult;
import com.st.buy.util.pojo.EasyUIDatagrideVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

/**
 * @author 张双虎
 */
@Controller
public class ContentController {


    @Autowired
    private RestTemplate restTemplate;
    @Value("${contentService}")
    private String contentServiceName;


    @RequestMapping("/content/save")
    @ResponseBody
    public BuyResult save(TbContent content){
        return restTemplate.postForObject("http://"+contentServiceName+"/content/save",content,BuyResult.class);
    }

    @RequestMapping("/content/query/list")
    @ResponseBody
    public EasyUIDatagrideVO<TbContent> queryList(@RequestParam(defaultValue = "1") long page, @RequestParam(defaultValue = "20") long rows,long categoryId){
        return restTemplate.getForObject("http://"+contentServiceName+"/content/list?page="+page+"&rows="+rows+"&categoryId="+categoryId, EasyUIDatagrideVO.class);
    }

}
